Skip to content

feat: programmatic form submissions#15657

Open
Rich-Harris wants to merge 11 commits intomainfrom
programmatic-submit
Open

feat: programmatic form submissions#15657
Rich-Harris wants to merge 11 commits intomainfrom
programmatic-submit

Conversation

@Rich-Harris
Copy link
Copy Markdown
Member

This implements #14082 (comment):

  • Remote form instances have a programmatic submit() method (await myform.submit())
  • This runs preflight checks, then submits the contents of the form (using the default submitter). It does not run logic inside an enhance callback
  • It returns a Promise with an updates method that can be used for optimistic updates
  • Enhance callbacks now receive a copy of the instance, rather than a { form, data, submit } object. (It's a copy because we don't want people to just call instance.submit() inside the enhance callback, since that would result in preflight validation running twice)

To facilitate this I made a small change to the implementation — instead of enhance(...) returning a fresh object, it just stashes away the callback for later. This is simpler and more consistent with how preflight works — it means you can do this, for example, without having to stash away a reference in order to spread it:

<script>
  import { myform } from './stuff.remote';

  myform.preflight(schema).enhance(async (f) => {
    // ...
  });
</script>

<form {...myform}>...</form>

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 5, 2026

🦋 Changeset detected

Latest commit: 60855ef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link
Copy Markdown

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@teemingc teemingc added the forms Stuff relating to forms and form actions label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

forms Stuff relating to forms and form actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants